﻿using System.Collections.Generic;
using UnityEngine;

public class ObjectController
{
    private List<GameObject> simpleBullets, purpleBullets, hollowCircleBullets, longBullets;
    
    public GameObject SimpleBullet()
    {
        if (simpleBullets == null)
        {
            simpleBullets = new List<GameObject>();
            simpleBullets.Add(PrefabRoot.SimpleBullet.GeneratePrefab(GameController.Instance().gameCore));
        }

        foreach (var bullet in simpleBullets)
        {
            if (bullet.activeSelf) continue;
            return bullet;
        }

        GameObject go = PrefabRoot.SimpleBullet.GeneratePrefab(GameController.Instance().gameCore);
        simpleBullets.Add(go);

        return go;
    }
    
    public GameObject HollowCircleBullet()
    {
        if (hollowCircleBullets == null)
        {
            hollowCircleBullets = new List<GameObject>();
            hollowCircleBullets.Add(PrefabRoot.HollowCircleBullet.GeneratePrefab(GameController.Instance().gameCore));
        }

        foreach (var bullet in hollowCircleBullets)
        {
            if (bullet.activeSelf) continue;
            return bullet;
        }

        GameObject go = PrefabRoot.HollowCircleBullet.GeneratePrefab(GameController.Instance().gameCore);
        hollowCircleBullets.Add(go);

        return go;
    }
    
    public GameObject PurpleBullet()
    {
        if (purpleBullets == null)
        {
            purpleBullets = new List<GameObject>();
            purpleBullets.Add(PrefabRoot.PurpleBullet.GeneratePrefab(GameController.Instance().gameCore));
        }

        foreach (var bullet in purpleBullets)
        {
            if (bullet.activeSelf) continue;
            return bullet;
        }

        GameObject go = PrefabRoot.PurpleBullet.GeneratePrefab(GameController.Instance().gameCore);
        purpleBullets.Add(go);

        return go;
    }
    
    public GameObject LongBullet()
    {
        if (longBullets == null)
        {
            longBullets = new List<GameObject>();
            longBullets.Add(PrefabRoot.LongBullet.GeneratePrefab(GameController.Instance().gameCore));
        }

        foreach (var bullet in longBullets)
        {
            if (bullet.activeSelf) continue;
            return bullet;
        }

        GameObject go = PrefabRoot.LongBullet.GeneratePrefab(GameController.Instance().gameCore);
        longBullets.Add(go);

        return go;
    }

}